package com.dundun.pattern.visitor;

import java.util.Iterator;

public class ListVisitor implements Vistitor {

    private String curdir = "";

    @Override
    public void visit(File file) {
        System.out.println(curdir + "/" + file);
    }

    @Override
    public void visit(Directory dir) {
        System.out.println(curdir + "/" + dir);
        String savedir = curdir;
        curdir += "/" + dir.getName();
        Iterator<Entry> it = dir.iterator();
        while (it.hasNext()) {
            it.next().accept(this);
        }
        curdir = savedir;
    }
}
